
#include <stdio.h>

#include "modules/audio_processing/agc/legacy/gain_control.h"
using namespace webrtc;

int main(void)
{
    int ret;

    void* agc = WebRtcAgc_Create();
    printf("WebRtcAgc_Create: %p \r\n", agc);
    
    /* possible mic level */
    int minLevel = 0, maxLevel = 100;
    /* 数字信号模式 */
    int16_t agcMode = kAgcModeAdaptiveDigital;
    ret = WebRtcAgc_Init(agc, minLevel, maxLevel, agcMode, 16000);
    printf("WebRtcAgc_Init: %d \r\n", ret);

    WebRtcAgcConfig config;
    ret = WebRtcAgc_get_config(agc, &config);
    printf("WebRtcAgc_get_config: %d \r\n", ret);

    config.targetLevelDbfs = 3; /* default 3 (-3 dBOv) */
    config.compressionGaindB = 9; /* 音量增益,数值越大声音越大, default 9 dB */
    config.limiterEnable = kAgcTrue; /* default kAgcTrue (on) */
    ret = WebRtcAgc_set_config(agc, config);
    printf("WebRtcAgc_set_config: %d \r\n", ret);

    /* 1x16000 10ms 数据量 */
    int16_t frame[160] = {0};
    /* 声道数据传参 */
    int16_t* in[1] = {NULL};
    int16_t* out[1] = {NULL};
    /* 装填输入输出(单声道配置) */
    in[0] = frame;
    out[0] = frame;
    /* 各声道的增益配置?用于数字信号 */
    int32_t gains[11] = {0};
    ret = WebRtcAgc_Process(
        agc,
        gains,
        (const int16_t* const*)in,
        1, /* 填声道数 */
        (int16_t* const*)out);
    printf("WebRtcAgc_Process: %d \r\n", ret);

    WebRtcAgc_Free(agc);
    printf("WebRtcAgc_Free\r\n");
    return 0;
}
